from flask import Flask, session, g
from views import *
from database import create_app
from models import User

app = create_app()

app.register_blueprint(home)
app.register_blueprint(auth)
app.register_blueprint(file)
app.register_blueprint(share)
app.register_blueprint(share_file)


@app.before_request
def my_before_request():
    user_id = session.get("user_id")
    if user_id:
        user = User.query.get(user_id)
        setattr(g, "user", user)
    else:
        setattr(g, "user", None)


@app.context_processor
def my_context_processor():
    return {"user": g.user}


if __name__ == "__main__":
    #certificate and key files
    # context = ('ca_crt/server.crt', 'ca_crt/server.key')
    # app.run(host='cainiao-e-station.cuc.edu.cn',ssl_context=context)
    app.run()
